*** Settings ***
Library           Selenium2Library

*** Variables ***
${url}            http://127.0.0.1:8000
${key_enter}      \\13

*** Test Cases ***
case-1
    Open Browser    http://127.0.0.1:8000    chrome    local
    ${title}    Get Title
    log    ${title}
    Open Browser    http://www.baidu.com    chrome    baidu
    ${title2}    Get Title
    log    ${title2}
    Switch Browser    local
    ${title}    Get Title
    log    ${title}
    Switch Browser    baidu
    ${title2}    Get Title
    log    ${title2}
    Close All Browsers

case-2-confirm
    Open Browser    http://127.0.0.1:8000    chrome
    Click Button    id=pay
    #Confirm Action
    Select Window    付款
    Log Source
    Close Browser

case-3-iframe
    Open Browser    http://127.0.0.1:8000    chrome
    Select Frame    id=fra
    ${list}    Get List Items    id=buy
    log    list=${list}
    Unselect Frame
    Log Source
    Close Browser

case-4-input
    Open Browser    ${url}    chrome
    Input Text    id=ProductName    new Product
    ${value}    Get Value    ProductName
    log    ProductName=${value}
    Assign Id To Element    name=Quantity    Quan
    Input Text    id=Quan    111
    ${qn}    Get Value    Quan
    log    quan=${qn}
    Close Browser

case-5-button
    Open Browser    ${url}    chrome
    Input Text    id=ProductName    new produceName
    Input Text    id=Quantity    111
    Click Button    id=submitBtn
    ${text}    Get Text    infoBtn
    log    text=${text}
    Close Browser

case-6-element-in-page
    ${value}    PrepareFun
    Input Text    id=Quantity    222
    Click Button    id=submitBtn
    ${text}    Get Text    infoBtn
    log    text=${text}
    ${text}    Get Element Attribute    Pr    innerText
    log     text=${text}
    ${name}    Get Element Attribute    ProductName    name
    log    name=${name}
    Close Browser

case-7-select
    Open
    Select From List By Label    selectdemo    第三个元素
    ${label}    Get Selected List Label    selectdemo
    log    label=${label}
    Select From List By Index    selectdemo    0
    ${value}    Get Selected List Value    selectdemo
    log    value=${value}
    Select From List By Value    selectdemo    item2
    ${label}    Get Selected List Label    selectdemo
    log    label=${label}
    Close Browser

case-8-checkbox-radio
    Open
    Click Element    CheckYes
    Select Checkbox    CheckNo
    UnSelect Checkbox    CheckYes
    Press Keys    CheckNo    ${key_enter}
    ${yes}    Get Value    CheckYes
    Select Radio Button    radio1    B
    ${radio}    Get Element Attribute    radioB    checked
    ${value}    Get Value    radioB
    Click Link    上传下载demo页面
    Sleep    2s
    ${title}    Get Title
    Close Browser

case-9-table
    Open
    ${cell}    Get Table Cell    buy    1    1
    ${cell}    Get Table Cell    buy    1    2
    Table Cell Should Contain    buy    1    1    产品
    Table Cell Should Contain     buy    1    2    数量
    Close Browser

case-10-cookie
    Open
    ${co}    Get Cookies
    Add Cookie    test    qitao
    Add Cookie    robot    framework
    ${co}    Get Cookies
    ${value}    Get Cookie    test
    Close Browser

case-11-js
    Open
    Execute Javascript    document.getElementById("infoBtn").disabled=false
    Execute Javascript    $("#ProductName").val("jquery")
    Execute Javascript    $("#Quantity").val("123")
    Execute Javascript    $("#submitBtn").click
    Sleep    5s
    ${pr}    Execute Javascript    return $("#Pr").html()
    ${qn}    Execute Javascript    return $("#Qn").html()
    Close Browser

case-12-capture
    Open
    Capture Page Screenshot
    Select Frame    id=fra
    Capture Page Screenshot    iframe.png
    Close Browser

case-13-wait
    Open
    Execute Javascript    document.getElementById("infoBtn").disabled=false
    Execute Javascript    $("#ProductName").val("jquery")
    Execute Javascript    $("#Quantity").val("123")
    Execute Javascript    $("#submitBtn").click
    WAit Until Page Contains    123
    ${pr}    Execute Javascript    return $("#Pr").html()
    ${qn}    Execute Javascript    return $("#Qn").html()
    Close Browser

*** Keywords ***
PrepareFun
    Open
    SetNameText
    ${value}    Get Value    ProductName
    log    value=${value}
    [Return]    ${value}

Open
    Open Browser    ${url}    chrome

SetNameText
    Input Text    id=ProductName    new Product
